1 00:00:00,610 --> 00:00:04,710 Now let's make our knockback for Chuck Norris kick. 2 00:00:04,720 --> 00:00:10,300 So I'm going to go to the move on PC, which should probably change because it's no longer just doing 3 00:00:10,300 --> 00:00:13,010 movement, but it's fine for now. 4 00:00:13,030 --> 00:00:14,300 Let's go. 5 00:00:14,320 --> 00:00:19,510 This is the top of the script where the variables are right underneath that. 6 00:00:19,840 --> 00:00:22,690 I'm going to make a function, local function. 7 00:00:22,720 --> 00:00:26,260 I'm going to call it knockback, and I'm going to keep this very general. 8 00:00:26,260 --> 00:00:31,750 So I'm not going to use any global variables because I want to move this to other things like my pistol, 9 00:00:31,750 --> 00:00:34,180 stuff like that or somebody else's punch. 10 00:00:34,180 --> 00:00:36,410 So I'm going to need two characters. 11 00:00:36,430 --> 00:00:44,020 I'm going to do one for the attack character and the other for the enemy character. 12 00:00:44,740 --> 00:00:45,060 Right? 13 00:00:45,250 --> 00:00:49,240 And I'll just do a quick check to see if the charge are there. 14 00:00:49,240 --> 00:01:00,040 So if a char and each are, then now I'm going to need the humanoid root parts of both of those and 15 00:01:00,040 --> 00:01:04,270 I know we have I humanoid root part, but like I said, I want to keep the self contained. 16 00:01:04,270 --> 00:01:05,470 So let's get it again. 17 00:01:05,470 --> 00:01:09,820 Let's call this a four attack humanoid root part. 18 00:01:09,850 --> 00:01:11,500 We're going to get it from the air. 19 00:01:12,520 --> 00:01:19,390 We'll do a find first child because if it's not there, we don't want to wait for it because it might 20 00:01:19,390 --> 00:01:27,640 take 2 seconds to come back in the world and we'll do a humanoid root part and then we'll do one for 21 00:01:27,640 --> 00:01:28,330 the enemy. 22 00:01:28,330 --> 00:01:29,380 HRP. 23 00:01:30,470 --> 00:01:32,630 Equals e char. 24 00:01:32,780 --> 00:01:36,050 Find first child. 25 00:01:36,630 --> 00:01:36,980 Whoops. 26 00:01:36,980 --> 00:01:38,270 I got a capital U in there. 27 00:01:38,300 --> 00:01:44,050 Don't put a capital U in their humanoid root part. 28 00:01:44,480 --> 00:01:45,620 I'm starting to lose it. 29 00:01:46,430 --> 00:01:50,760 All right, now let's do a check for those just to make sure that they were found. 30 00:01:50,780 --> 00:02:02,330 So I'll say if a HPE and e HPE, then now we need to find the direction between those two characters 31 00:02:02,330 --> 00:02:07,520 or those two humanoid root parts because we want to send them send the person who's getting knocked 32 00:02:07,520 --> 00:02:08,900 back back, right? 33 00:02:08,900 --> 00:02:12,680 We don't want them to just go behind us or go in any random direction. 34 00:02:12,680 --> 00:02:18,440 So let's get a direction vector, say local deer. 35 00:02:18,800 --> 00:02:28,430 I want to get my hr p position, subtract it from my a hpe's position. 36 00:02:28,430 --> 00:02:28,850 Right? 37 00:02:28,850 --> 00:02:32,110 So that's a direction vector, but we don't know the length. 38 00:02:32,120 --> 00:02:40,190 Let's make it a unit vector so we can calculate force and we're just getting the direction and so the 39 00:02:40,190 --> 00:02:42,080 vectors of magnitude one. 40 00:02:42,740 --> 00:02:43,100 All right. 41 00:02:43,100 --> 00:02:50,330 Now the new body movers like vector force and angular force need an attachment that's slightly different 42 00:02:50,330 --> 00:02:55,190 than the old ones if you're used to the body, the body movers. 43 00:02:55,490 --> 00:02:57,320 So let's make an attachment. 44 00:02:57,470 --> 00:03:01,610 Let's say eight for attachment instance. 45 00:03:01,640 --> 00:03:04,730 No attachment. 46 00:03:05,030 --> 00:03:06,200 There it is. 47 00:03:06,200 --> 00:03:09,050 And we will parent it to the enemy. 48 00:03:09,050 --> 00:03:10,640 Humanoid root part. 49 00:03:11,840 --> 00:03:13,910 And now I'm going to need a vector force. 50 00:03:13,910 --> 00:03:15,560 I'll just call the F. 51 00:03:15,800 --> 00:03:23,660 That's going to be an instance new vector force, and I will make that on the humanoid root part. 52 00:03:25,590 --> 00:03:33,060 Now we need to get the vector forces attachment zero and a sign attached to it. 53 00:03:34,130 --> 00:03:37,280 And now we'll get the vector forces force. 54 00:03:37,460 --> 00:03:40,190 We're going to use our dir. 55 00:03:40,220 --> 00:03:45,710 The direction vector was a deer, but I wanted to go up a little bit. 56 00:03:45,710 --> 00:03:45,940 Right. 57 00:03:45,950 --> 00:03:48,950 So I want to knock them in the air, not just straight back. 58 00:03:48,950 --> 00:03:53,350 So let's add a vector three dot new. 59 00:03:53,540 --> 00:03:59,000 We'll do zero and one and zero. 60 00:03:59,990 --> 00:04:07,670 I'll go ahead and normalize that to the unit vector to also, I should say, and then I'm going to multiply 61 00:04:07,670 --> 00:04:10,610 this by 10,000. 62 00:04:11,540 --> 00:04:15,650 That might be that might be too much, but we can play around with these numbers. 63 00:04:15,650 --> 00:04:22,310 So if you want to take the force going back up upwards and away, you're going to reduce this number 64 00:04:22,310 --> 00:04:23,300 right here. 65 00:04:24,710 --> 00:04:32,030 Now let's do v f, and we have to choose whether we want to do relative to the world or relative to 66 00:04:32,030 --> 00:04:33,320 the attachment. 67 00:04:33,320 --> 00:04:33,740 Right? 68 00:04:33,740 --> 00:04:43,430 So we have our vector force relative to e m, and this is crazy actuator relative to, Oh, I haven't 69 00:04:43,430 --> 00:04:47,540 done anything with actuators in this course, so activate a relative to its OC. 70 00:04:47,570 --> 00:04:52,550 They just use the e name for this for a lot of different things that have attachments where you're going 71 00:04:52,550 --> 00:04:57,260 to have an issue of whether you want to relative to the attachment or relative to the world. 72 00:04:57,260 --> 00:04:59,030 We're going to pick the world. 73 00:04:59,690 --> 00:05:01,430 And then what else do we need? 74 00:05:02,690 --> 00:05:10,340 0vf We need to know whether we want to apply the force at the center of mass. 75 00:05:10,340 --> 00:05:13,670 And we do or where it's attached, right? 76 00:05:13,670 --> 00:05:15,020 Those are your two options. 77 00:05:15,020 --> 00:05:16,610 So we'll say true. 78 00:05:16,610 --> 00:05:18,800 Apply to center of mass. 79 00:05:19,130 --> 00:05:21,980 Now we need our rotational force. 80 00:05:21,980 --> 00:05:23,180 Let's go up a little bit. 81 00:05:24,580 --> 00:05:28,570 So I'll call that root for rotation. 82 00:05:28,750 --> 00:05:30,370 And what have we got? 83 00:05:30,370 --> 00:05:40,540 Instance Dot knew we need angular velocity for this, and then that's going to be on the enemy humanoid 84 00:05:40,540 --> 00:05:41,440 root part. 85 00:05:41,950 --> 00:05:44,700 We'll get our rot. 86 00:05:44,710 --> 00:05:49,620 Let's use attachment, the attachment we created above that attached. 87 00:05:49,630 --> 00:05:53,920 So we'll put the rotational force on that same attachment. 88 00:05:54,880 --> 00:06:00,160 Let's see now let's do rot angular velocity. 89 00:06:01,200 --> 00:06:01,390 All right. 90 00:06:01,480 --> 00:06:04,930 And this is going to be a vector three new. 91 00:06:04,990 --> 00:06:07,330 I'll make a one by one by one. 92 00:06:07,600 --> 00:06:13,270 And this is going to be how many times something spins around per unit of time. 93 00:06:13,450 --> 00:06:15,900 30 gives it a pretty good spin. 94 00:06:15,910 --> 00:06:18,040 So this is a this is a vector. 95 00:06:18,040 --> 00:06:22,900 But if we multiply it by a scalar, it's going to be 30, 30 and 30. 96 00:06:22,900 --> 00:06:25,840 I just think it's easier to change if you're playing around with numbers. 97 00:06:25,840 --> 00:06:30,010 If you have the scalar on the end, what else are we going to need? 98 00:06:30,010 --> 00:06:36,770 We're going to need wrought max torque and we'll just make that math huge, right? 99 00:06:36,790 --> 00:06:39,190 So that's the maximum torque we can apply. 100 00:06:39,190 --> 00:06:41,440 We want to apply as much as we need. 101 00:06:42,340 --> 00:06:42,610 All right. 102 00:06:42,610 --> 00:06:50,050 We'll do the game debris service to clean up all these parts that we put on somebody's humanoid root 103 00:06:50,050 --> 00:06:50,690 part. 104 00:06:50,710 --> 00:06:53,470 We'll do a add item. 105 00:06:53,590 --> 00:06:56,460 So we have our vector force you have to get rid of. 106 00:06:56,470 --> 00:07:04,720 We'll let it live for 0.2 seconds because the vector force will continue to push on the character and 107 00:07:04,720 --> 00:07:07,060 it'll fly away forever if we don't destroy it. 108 00:07:07,330 --> 00:07:11,710 So we'll do game debris, service, colon. 109 00:07:11,710 --> 00:07:15,250 We need an add item for the attachment. 110 00:07:15,250 --> 00:07:24,910 We'll make that point two I will do game debris, add item for the rot, the rotational force make that 111 00:07:24,910 --> 00:07:25,930 point too. 112 00:07:26,350 --> 00:07:34,330 So for a quick recap, we have two forces acting on our enemies humanoid root part using this attachment 113 00:07:34,330 --> 00:07:37,840 which is attached to the humanoid root part, the enemy's humanoid root part. 114 00:07:37,840 --> 00:07:41,380 So we have a vector force which is going to push them back. 115 00:07:41,380 --> 00:07:45,220 And we also have this angular velocity, right? 116 00:07:45,220 --> 00:07:49,300 That's rot and that's going to spin them, right? 117 00:07:49,300 --> 00:07:51,430 And we're always going to spin in the same direction. 118 00:07:51,430 --> 00:07:55,030 These are axes of rotation right here. 119 00:07:55,300 --> 00:07:57,970 And let's go ahead and try it out, see what we got. 120 00:07:57,970 --> 00:07:59,320 We've got to call this first. 121 00:07:59,320 --> 00:08:07,000 Remember, we have our attacking char and our enemy char go down to where we do our kick. 122 00:08:07,000 --> 00:08:12,400 So whenever you go to apply that knockback, you're going to look for where you take damage. 123 00:08:12,820 --> 00:08:14,950 Let's see, we do this. 124 00:08:14,950 --> 00:08:17,350 Let's do the damage. 125 00:08:18,290 --> 00:08:22,610 Let's do the knockback right after we do the damage. 126 00:08:22,610 --> 00:08:24,590 So I'll say knockback. 127 00:08:25,490 --> 00:08:27,740 I want my attacking help. 128 00:08:27,770 --> 00:08:28,730 Well, that's easy enough. 129 00:08:28,730 --> 00:08:32,150 That's our I, not HP NPC. 130 00:08:32,270 --> 00:08:37,460 We need our AI NPC and we need the enemies chart. 131 00:08:37,490 --> 00:08:39,920 We don't have the enemies cha. 132 00:08:40,100 --> 00:08:44,850 We do have the closest humanoid root part though. 133 00:08:44,870 --> 00:08:46,190 That's all right. 134 00:08:46,190 --> 00:08:53,080 Because if we have the closest humanoid root part or the closest humanoid, the parent is the cha, 135 00:08:53,090 --> 00:08:54,640 we are good to go. 136 00:08:54,650 --> 00:08:56,180 Let's see what we got. 137 00:08:56,900 --> 00:08:58,190 Hit the play button. 138 00:09:00,420 --> 00:09:01,830 MPC work. 139 00:09:02,040 --> 00:09:02,800 Here we go. 140 00:09:02,820 --> 00:09:03,750 There's Chuck. 141 00:09:04,530 --> 00:09:05,080 Maybe. 142 00:09:05,130 --> 00:09:06,180 Should we put our. 143 00:09:06,300 --> 00:09:07,500 Let's get our output window. 144 00:09:07,500 --> 00:09:08,190 We'll check it out for you. 145 00:09:08,220 --> 00:09:08,880 Kicks us. 146 00:09:09,390 --> 00:09:10,620 Boom. 147 00:09:10,830 --> 00:09:12,330 Pretty cool. 148 00:09:13,290 --> 00:09:14,100 Do it again. 149 00:09:14,670 --> 00:09:15,650 We'll do with that. 150 00:09:15,660 --> 00:09:17,160 We'll do it with the output window. 151 00:09:22,460 --> 00:09:23,570 Nice. 152 00:09:23,990 --> 00:09:25,070 I'm liking it. 153 00:09:27,420 --> 00:09:27,870 All right. 154 00:09:27,870 --> 00:09:28,770 That's pretty cool. 155 00:09:28,770 --> 00:09:33,150 And we can create the distance of it or we can increase the distance of interest if we want them to 156 00:09:33,150 --> 00:09:34,620 chase after us to.